//
//  GCSettingViewController.m
//  GoldChampion
//
//  Created by Mac on 2018/4/11.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "GCPrivacySettingViewController.h"
#import "GCChosePeopleViewController.h"
#import "GHBlacklistViewController.h"
@interface GCPrivacySettingViewController ()
@property(nonatomic, strong) NSArray                     *dataSouce;
@property(nonatomic, strong) UISwitch                     *shuiyingSwitch;
@property(nonatomic, strong) UISwitch                     *weizhiSwitch;
@property(nonatomic, strong) UISwitch                     *yinsiSwitch;
@property(nonatomic, strong) UISwitch                     *guanzhuSwitch;
@property(nonatomic, strong) UISwitch                     *haoyouSwitch;
@end

@implementation GCPrivacySettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"隐私设置";
    [self configDataSouce];
    
    // Do any additional setup after loading the view.
}

- (void)configDataSouce{
    
    
    self.shuiyingSwitch = [self deflutSwitch];
    self.weizhiSwitch = [self deflutSwitch];
    self.yinsiSwitch = [self deflutSwitch];
    self.guanzhuSwitch = [self deflutSwitch];
    self.haoyouSwitch = [self deflutSwitch];
    
    
    STTableEasyModel * shuiyingModel =  [[STTableEasyModel alloc] initWithTextString:@"水印设置"
                                                                    accessoryView:self.shuiyingSwitch];

    

    STTableEasyModel * weizhiModel =  [[STTableEasyModel alloc] initWithTextString:@"隐藏位置信息"
                                                                       accessoryView:self.weizhiSwitch];
    
    STTableEasyModel * yinsiModel =  [[STTableEasyModel alloc] initWithTextString:@"隐私用户"
                                                                     accessoryView:self.yinsiSwitch];
    
    STTableEasyModel * guanzhuModel =  [[STTableEasyModel alloc] initWithTextString:@"只允许我关注的人评论我"
                                                                    accessoryView:self.guanzhuSwitch];
    
    STTableEasyModel * haoyouModel =  [[STTableEasyModel alloc] initWithTextString:@"不把我推荐给通讯录好友"
                                                                      accessoryView:self.haoyouSwitch];
    
    
    NSArray * section0 =  @[shuiyingModel];
    
    NSArray * section1 =  @[weizhiModel];
    NSArray * section2 =  @[yinsiModel];
    NSArray * section3 =  @[guanzhuModel,
                            [[STTableEasyModel alloc] initWithTextString:@"谁可以私信我"
                                                           detailString:@"所有人"]
                            ];
    NSArray * section4 =  @[haoyouModel];
    NSArray * section5 =  @[
                            [[STTableEasyModel alloc] initWithTextString:@"黑名单"
                                                            detailString:@""]
                            ];
    self.dataSouce = @[
                       section0,
                       section1,
                       section2,
                       section3,
                       section4,
                       section5
                       ];
    [self.tableView reloadData];
    
}
- (UISwitch*)deflutSwitch{
    UISwitch * switchView = [UISwitch new];
    switchView.onTintColor = UIColorFromRGBA(0x3ECD74);
    [switchView addTarget:self action:@selector(switchViewChangedValue:) forControlEvents:UIControlEventValueChanged];
    return switchView;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.dataSouce.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [self.dataSouce[section] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 55;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 2 || section == 3 || section == 5) {
        if (section == 5) {
            return 60;
        }
        return 44;
    }
    return 24;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 2 ) {
        return [TMUtils sectionHeaderWithTitle:@"打开时,你的作品在同城页面不可见"];
    }
    if (section == 3) {
       return [TMUtils sectionHeaderWithTitle:@"别人关注你需要你的允许,作品只展示给已关注你的人"];
    }
    if (section == 5) {
        UIView * sectionHeder = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 60)];
        STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(15, 0, UIScreenWidth-30, 60)
                                                         text:@"打开后，你的通讯录好友将无法看到你; 此功能需要先绑定手机号并关联通讯录后才能开启。"
                                                    textColor:SecendTextColor
                                                         font:14
                                                  isSizetoFit:NO
                                                textAlignment:NSTextAlignmentLeft];
        [sectionHeder addSubview:titleLable];
        return sectionHeder;
    }
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
        
    }
    STTableEasyModel * model = self.dataSouce[indexPath.section][indexPath.row];
    [cell setSt_tableEasyModel:model];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    STTableEasyModel * model = self.dataSouce[indexPath.section][indexPath.row];
    if ([model.textString containsString:@"黑名单"]) {
        [self.navigationController pushViewController:[GHBlacklistViewController new] animated:YES];
    }
    if ([model.textString containsString:@"谁可以私信我"]) {
        GCChosePeopleViewController * vc = [GCChosePeopleViewController new];
        vc.currentName = model.detailString;
        [vc setChosedHandle:^(NSString *name) {
            model.detailString = name;
            [self.tableView reloadData];
        }];
        [self.navigationController pushViewController:vc animated:YES];
    }
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}

#pragma mark --Action Method
- (void)switchViewChangedValue:(UISwitch*)sender{
    
}

@end


